//
//  HJRepairtGroupMainCell.m
//  GAMCAfterSales
//
//  Created by 贺佳 on 2018/7/30.
//  Copyright © 2018年 glendale. All rights reserved.
//

#import "HJRepairtGroupMainCell.h"

#import "HJCommonModel.h"

@interface HJRepairtGroupMainCell()
/**
 序号
 */
@property(nonatomic,weak)UILabel*noLabel;
/**
 选择按钮
 */
@property(nonatomic,weak)UIButton*selectBtn;
/**
 维修车型
 */
@property(nonatomic,weak)UILabel*carTypeLabel;
/**
 维修代码
 */
@property(nonatomic,weak)UILabel*codeLabel;
/**
 维修名称
 */
@property(nonatomic,weak)UILabel*nameLabel;
/**
 车型组缓存数据
 */
@property(nonatomic,strong)NSMutableArray*arrDisDataForCarType;
@end
@implementation HJRepairtGroupMainCell
/** 维修车型组 */
-(NSMutableArray *)arrDisDataForCarType{
    if (_arrDisDataForCarType == nil) {
        NSMutableArray *arr = [HJLocalDataManager sharedInstance].cacheDict[@"TM_MODEL_LABOUR"];
        _arrDisDataForCarType=[HJCommonModel mj_objectArrayWithKeyValuesArray:arr];
    }
    return _arrDisDataForCarType;
}
UITablecellM(@"HJRepairtGroupMainCell")
-(void)setUI{
    //序号
    UILabel*noLabel=[self createLabel];
    self.noLabel=noLabel;
    [self.contentView addSubview:noLabel];
    WEAKSELF;
    [noLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView);
        make.top.bottom.mas_equalTo(weakSelf.contentView);
        make.width.mas_equalTo(weakSelf.contentView).multipliedBy(0.1);
    }];
    
    //选择按钮
    UIButton*selectBtn=[[UIButton alloc]init];
    [self.contentView addSubview:selectBtn];
    self.selectBtn=selectBtn;
    [selectBtn setImage:[UIImage imageNamed:@"对号框.png"] forState:UIControlStateNormal];
    [selectBtn setImage:[UIImage imageNamed:@"对号.png"] forState:UIControlStateSelected];
    [selectBtn addTarget:self action:@selector(clickSelectGroup:) forControlEvents:UIControlEventTouchUpInside];
    [selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(noLabel.mas_right);
        make.top.bottom.mas_equalTo(noLabel);
        make.width.mas_equalTo(noLabel);
    }];
    
    //维修车型
    UILabel*carTypeLabel=[self createLabel];
    [self.contentView addSubview:carTypeLabel];
    self.carTypeLabel=carTypeLabel;
    [carTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(selectBtn.mas_right);
        make.top.bottom.mas_equalTo(selectBtn);
        make.width.mas_equalTo(weakSelf.contentView).multipliedBy(0.3);
        
    }];
    
    //维修代码
    UILabel*codeLabel=[self createLabel];
    [self.contentView addSubview:codeLabel];
    self.codeLabel=codeLabel;
    [codeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(carTypeLabel.mas_right);
        make.top.bottom.mas_equalTo(selectBtn);
        make.width.mas_equalTo(weakSelf.contentView).multipliedBy(0.2);
        
    }];
    
    //维修名称
    UILabel*nameLabel=[self createLabel];
    [self.contentView addSubview:nameLabel];
    self.nameLabel=nameLabel;
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(codeLabel.mas_right);
        make.top.bottom.mas_equalTo(selectBtn);
        make.width.mas_equalTo(weakSelf.contentView).multipliedBy(0.3);
        
    }];

}
-(UILabel*)createLabel{
    UILabel*label=[[UILabel alloc]init];
    label.font=HJFont(13);
    label.textAlignment=NSTextAlignmentCenter;
    return label;
}
-(void)clickSelectGroup:(UIButton*)btn{
    btn.selected=!btn.selected;
    self.TM_PACKAGEModel.isSelect=btn.selected;
    if ([_delegate respondsToSelector:@selector(repairtGroupMainCell:clickSelectGroup:isSelect:)]) {
        [_delegate repairtGroupMainCell:self clickSelectGroup:self.TM_PACKAGEModel isSelect:btn.selected];
    }
}
-(void)setTM_PACKAGEModel:(HJRepairtGroupTM_PACKAGEModel *)TM_PACKAGEModel
{
    _TM_PACKAGEModel=TM_PACKAGEModel;
    
    
   self.selectBtn.selected=TM_PACKAGEModel.isSelect;
   
    self.carTypeLabel.text=@"";
    for (HJCommonModel*model in self.arrDisDataForCarType) {
        if ([model.CODE isEqualToString:TM_PACKAGEModel.MODEL_LABOUR_CODE]) {
            self.carTypeLabel.text=model.NAME;
        }
    }
    
   self.codeLabel.text=TM_PACKAGEModel.PACKAGE_CODE;
    self.nameLabel.text=TM_PACKAGEModel.PACKAGE_NAME;
    
}
-(void)setRow:(NSInteger)row
{
    _row=row;
    self.noLabel.text=[NSString stringWithFormat:@"%zd",row];
}
@end
